#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif 
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#define serial_port_name "COM3"
#else
#define serial_port_name "/dev/ttyACM0"
#endif 
#include<common/mavlink.h>
#include<mavlink_types.h>
#include<mavlink_helpers.h>
#include<asio.hpp>
#include<functional>
namespace mav{

	class mavio
	{
	public:
		mavio(asio::serial_port &ser);
		mavio(asio::ip::udp::socket & ser);
		std::function<void(unsigned char)> send;
		void setReceivedFunc(std::function<void(unsigned char)>func);
		~mavio();
		operator void* () {
			return (void*)this;
		}
	private:

		unsigned char bufchar[1024];
		asio::mutable_buffers_1 bufvec;
		void emptyfunc() {};
		std::function<void(unsigned char)> received = NULL;
		asio::serial_port *serial;
		asio::ip::udp::socket *udp;
		void serReceivedfunc();
		void socReceivedfunc();
	};

	void bind_mavio_to(unsigned char num, mavio& mav);
	mavio& get_mavio(unsigned char num);
}
